package com.db.ionio.serialization;

import java.io.InputStream;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.OutputStream;

/**
 * @author Alexander Kotov (kotov.alex.22@gmail.com)
 */
public class JavaSerializer<T> implements Serializer<T> {
    @Override
    public void serialize(T obj, OutputStream outStream) throws Exception {
        ObjectOutputStream objectOutputStream = new ObjectOutputStream(outStream);
        objectOutputStream.writeObject(obj);
    }

    @Override
    public T deserialize(InputStream inStream) throws Exception {
        ObjectInputStream objectInputStream = new ObjectInputStream(inStream);
        return (T)objectInputStream.readObject();
    }

    @Override
    public String getType() {
        return "java";
    }
}
